package home.contaduria.domain;

import java.io.Serializable;

import org.apache.commons.lang.SerializationUtils;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

public abstract class AbstractBean implements Serializable, Cloneable {

	private static final long serialVersionUID = -4651248528052139444L;

	@Override
	public boolean equals(Object obj) {
		return EqualsBuilder.reflectionEquals(this, obj, false, null, declareExcludeFields());
	}

	@Override
	public int hashCode() {
		return HashCodeBuilder.reflectionHashCode(this, declareExcludeFields());
	}

	@Override
	protected Object clone() throws CloneNotSupportedException {
		return SerializationUtils.clone(this);
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE, false, null);
	}

	/**
	 * Declares field names that will not be tested. This method used by
	 * {@link DataTransferObject#equals(Object)}.
	 * <p/>
	 * By default method returns an empty array. It means that all class data
	 * members, if there are not any specific restrictions, will be tested.
	 * 
	 * @return the array of the field names that will not be tested, not
	 *         <code>null</code>.
	 */
	protected String[] declareExcludeFields() {
		return new String[0];
	}
}
